package com.wxsong.authplatform.authweb.dao.menu;

import com.google.common.collect.Maps;
import com.wxsong.authplatform.authweb.dao.BaseDao;
import com.wxsong.authplatform.authweb.model.menu.Menu;
import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public class MenuDao extends BaseDao {

    public Menu getByName(String userName){
        return this.getSqlSession().selectOne("MenuMap.selectByName", userName);
    }

    public Menu getById(Long id){
        return this.getSqlSession().selectOne("MenuMap.selectById", id);
    }

    public List<Menu> list(int from, int pageSize, Map<String, Object> paramMap){
        paramMap.put("from", from);
        paramMap.put("size", pageSize);
        return this.getSqlSession().selectList("MenuMap.selectList", paramMap);
    }

    public Long count(Map<String, Object> paramMap){
        return this.getSqlSession().selectOne("MenuMap.selectCount", paramMap);
    }

    public int add(Menu users){
        return this.getSqlSession().insert("MenuMap.insertMenu", users);
    }

    public int update(Map paramMap){
        return this.getSqlSession().insert("MenuMap.updateMenu", paramMap);
    }

    public int delete(Long[] ids){
        return this.getSqlSession().delete("MenuMap.deleteMenu", ids);
    }

    public List<Menu> getByParentId(Long parentId) {
        return this.getSqlSession().selectList("MenuMap.selectByParentId", parentId);
    }

    public List<Menu> getByParentCode(String parentCode, long curUserId) {
        Map<String, Object> paramMap = Maps.newHashMap();
        paramMap.put("parentCode", parentCode);
        paramMap.put("curUserId", curUserId);
        return this.getSqlSession().selectList("MenuMap.selectByParentCode", paramMap);
    }

    public List<Menu> findOwnFirstMenuByRoles(Long[] ids) {
        return this.getSqlSession().selectList("MenuMap.selectFirstMenuByRoles", ids);
    }
}
